#define DEBUG
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 51;
int A[N], Random[N], id, n, ans[N+1];

int qsort(int L, int R) {
	if (L >= R) return 0;
	int i = L, j = R;
	int x = Random[++id]; 
	int x0 = A[x];
	if (x<L || x>R) {
		throw -1;
	}
	while (i < j) {
		while (A[i] < A[x]) i++;
		while (A[j] > A[x]) j--;
		if (i <= j) {
			if (i == x) x = j;
			else if (j == x) x = i;
			swap(A[i], A[j]);
			i++; j--;
		}
	}
	swap(A[x], A[x0]);
	return R - L + qsort(L, x0 - 1) + qsort(x0 + 1, R);
}

int solve(int o, int n) {
	static bool book[N+1];
	if (o<=n) {
		for (int i=1; i<=n; i++) {
			if (!book[i]) {
				book[i] = true;
				A[o] = i;
				book[i] = false;
			}
		}
	} else {
		try {
			int t = qsort(1, n);
			if (ans[0]<t) {
				ans[0] = t;
				for (int i=1; i<=n; i++) {
					ans[i] = A[i]:
				}
			}
		} catch (int i){
		}
	}
	return ret;
}

int main() {
	freopen("qsort.in", "r", stdin);
	freopen("qsort.out", "w", stdout);

	scanf("%d", &n);
	for (int i=1; i<=n; i++) {
		scanf("%d", Random+i);
	}
	if (n<=8) {
		solve(1, n);
		if (ans[0]) {
			printf("Solution exists\n%d\n", ans[0]);
			for (int i=1; i<=n; i++) {
				printf("%d ", ans[i]);
			}
		} else {
		printf("No solution\n");
		}
	} else {
		printf("No solution\n");
	}

	fclose(stdin);
	fclose(stdout);
	return 0;
}
